<template>
	<view class="myaddress">
		<view v-for="(item,index) in addrsList" :key="item.id" class="address_cell">
			<uni-icons type="location" size="24" color="#00A0DC"></uni-icons>
			<view class="flex-1 ml-5 mr-15" @click="choiceAddrs(index)">
				<view class="display_flex">
					<view class="f-15">{{item.name}}</view>
					<view class="f-15 c-999999 ml-5">{{item.mobile}}</view>
					<view v-if="item.status==1" class="def_btn ml-5">默认</view>
				</view>
				<view class="f-12 c-gray mt-5">{{item.area.province_name}}{{item.area.city_name}}{{item.area.area_name}}{{item.address}}</view>
			</view>
			<view @click="editAddress(1,index)">
				<uni-icons type="compose" size="24" color="#00A0DC"></uni-icons>
			</view>
			<!-- <view class="ml-10">
				<uni-icons type="trash" size="24" color="#F03636" @click="delAddress()"></uni-icons>
			</view> -->
		</view>
		<view class="next_step_btn" @click="editAddress(2)">
			<uni-icons type="plusempty" size="14" color="#ffffff"></uni-icons>
			添加地址
		</view>
	</view>
</template>

<script>
	import {
		getShopAddrlist,
	} from '@/api/motortime.js';
	let app = getApp()
	export default {
		data() {
			return {
				addrsList: []
			};
		},
		onShow() {
			this.getShopAddrlist()
		},
		onLoad() {

		},
		methods: {
			getShopAddrlist() {
				getShopAddrlist({}).then(res => {
					if (res.state == 1) {
						uni.hideLoading()
						this.addrsList = res.data
					} else {
						uni.hideLoading()
						this.loadingTitle = "- 暂无更多 -"
						uni.showToast({
							title: res.error[0],
							mask: true,
							icon: 'none',
							duration: 1500
						})
					}
				})
			},
			editAddress(type, index) {
				if (type == 1) {
					uni.setStorage({
						key: 'taskAddrInfo',
						data: this.addrsList[index]
					})
				}
				uni.navigateTo({
					url: '/pages/my/editaddress'
				})
			},
			choiceAddrs(index) {
				uni.setStorage({
					key: 'taskAddrInfo',
					data: this.addrsList[index]
				})
				uni.navigateBack({
					delta: 1
				})
			}
		},
	}
</script>

<style lang="scss">
	.myaddress {
		.address_cell {
			padding: 30rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			border-bottom: 1rpx solid #E9E9E9;

			.def_btn {
				color: #00A0DC;
				font-size: 20rpx;
				padding: 2rpx 10rpx;
				border-radius: 8rpx;
				border: 1rpx solid #00A0DC;
			}
		}

		.next_step_btn {
			display: flex;
			align-items: center;
			justify-content: center;
			color: #ffffff;
			padding: 20rpx 0;
			margin: 60rpx 30rpx;
			border-radius: 8rpx;
			background-color: #00A0DC;
		}
	}
</style>